// 常见的异步操作有计时器、fs模块、ajax等
const fs = require('fs')
fs.readFile('./boo.txt',(err,data)=>{
    if(err) throw err
    console.log(data.toString())
})
用Promise封装fs
// const p = new Promise((resolve, reject) => {
//     const fs = require('fs')
//     fs.readFile('./book.txt', (err, data) => {
//         if (err)reject(err)
//         resolve(data)
//     })
// })
// p.then((data)=>{console.log(data.toString())},(message)=>{console.log(message)})



const p=new Promise((resolve,reject)=>{
    resolve()
})
const then1 =p.then(()=>{throw 'throw返回了的'},()=>{})
const then2 =p.then(()=>'非promise对象返回的',()=>{})
const then3 =p.then(()=>new Promise((resolve,reject)=>{resolve('promise对象返回的')}),()=>{})
console.log(then1,then2,then3)
